package api.Order;
import com.alibaba.fastjson2.JSON;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Map;

@WebServlet("/api/order/*")
public class GetOrder extends HttpServlet {
    protected final ImplUseOrder implUseOrder = new ImplUseOrder();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        Map<String, Object> body = JSON.parseObject((String) req.getAttribute("body"));
        String uri = req.getRequestURI();
        if(uri.equals("/api/order/add")) resp.getWriter().write(implUseOrder.addOrder((String) req.getAttribute("body")));
        if(uri.equals("/api/order/id")) resp.getWriter().write(implUseOrder.getOrderById((Integer) body.get("id")));
        if(uri.equals("/api/order/uid")) resp.getWriter().write(implUseOrder.getUserOrderById(body.get("id").toString()));
    }
}
